package main

import "fmt"

type Animal interface {
	Speak() string
}

type Dog struct {
	Address string
}

func (d Dog) Speak() string {
	println("汪汪汪")
	return "金色的狗"
}

type Cat struct {
	Name string
}

func (c Cat) Speak() string {
	println("喵喵喵")
	return "这是一只灰色"
}

// Animal2 动物继承
type Animal2 struct {
	Dog
	Cat
	// 腿
	Legs int
}

func (a Animal2) Speak() string {
	println("这是", a.Legs, "只腿")
	return "1"
}

func main() {
	a := Animal2{
		Legs: 4,
		Dog:  Dog{"北京"},
		Cat:  Cat{"小猫"},
	}
	d := a.Dog.Speak()
	fmt.Printf("这是%s的%s\n", a.Address, d)
	c := a.Cat.Speak()
	fmt.Printf("%s的%s\n", c, a.Name)
	//var animal Animal
	animal := []Animal{a}
	for _, i2 := range animal {
		i2.Speak()
	}
}
